package cn.tedu.egweibo2.controller;

import cn.tedu.egweibo2.mapper.UserMapper;
import cn.tedu.egweibo2.pojo.dto.UserDTO;
import cn.tedu.egweibo2.pojo.entity.User;
import cn.tedu.egweibo2.pojo.vo.UserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Date;

/**
 * @author Justin Parker
 * @author 2024/8/11 22:23
 * @version 1.0
 */
@Slf4j
@Api(tags = "用户模块")
@RestController
@RequestMapping("/eg/weibo2")
public class UserController {
    @Autowired
    private UserMapper userMapper;

    @PostMapping("/reg")
    @ApiOperation(value = "注册")
    public int reg( @RequestBody UserDTO userDTO){
        log.debug("日志信息"+"userDTO = {}",userDTO);
        String username = userDTO.getUsername();
        UserVO userVO = userMapper.selectByUsername(username);
        if (userVO != null){
            return 0;
        }
        User user = new User();
        BeanUtils.copyProperties(userDTO,user);
        user.setCreated(new Date());
        userMapper.insert(user);
        return 1;

    }
}
